const handleTitleList = (itemList) => {
    let titleList = itemList.reduce((result, data) => {
        if (
            data.JobGroup &&
            !result.some((sitm) => sitm.levelName == data.JobGroup)
        ) {
            result.push({
                levelName: data.JobGroup,
                levelList: [],
            });
        }
        let levelObj = result.find((d) => d.levelName == data.JobGroup);

        if (levelObj) {
            if (levelObj.levelName == data.JobGroup) {
                if (!levelObj.levelList) {
                    levelObj.levelList = []
                }

                levelObj.isShow = true
                //levelDataType.DataTypeIndex = data.DataTypeIndex
                levelObj.levelList.push({
                    levelName: data.JobItemName,
                    levelValue: data.SectionResultStr,
                    levelDataType: data.DataTypeIndex,
                    JobRecordDetailID: data.JobRecordDetailID,
                    SectionResultStr: data.SectionResultStr,
                });
            }
        } else {
            result.push({
                levelName: data.JobItemName,
                levelValue: data.SectionResultStr,
                levelDataType: data.DataTypeIndex,
                JobRecordDetailID: data.JobRecordDetailID,
                SectionResultStr: data.SectionResultStr,
                isShow: false,
            });
        }

        return result;
    }, []);
    return titleList;
}

export default { handleTitleList }